package com.sneaker.shower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sneaker.shower.entity.domain.menu.ProductDO;
import com.sneaker.shower.entity.dto.ProductDTO;
import com.sneaker.shower.mapper.ProductMapper;
import com.sneaker.shower.mapstruct.ProductMapStruct;
import com.sneaker.shower.service.ProductService;
import com.sneaker.shower.util.JacksonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> implements ProductService {

    @Override
    public Map<String, List<ProductDTO>> listProductByMenuGuid(List<String> menuGuidList) {
        if (CollectionUtils.isEmpty(menuGuidList)) {
            log.info("通过menuGuid查询产品列表入参为空");
            return null;
        }
        List<ProductDO> list = list(new LambdaQueryWrapper<ProductDO>().in(ProductDO::getMenuGuid, menuGuidList));
        if (CollectionUtils.isEmpty(list)) {
            log.info("该菜单【{}】下没有产品信息", JacksonUtils.writeValueAsString(menuGuidList));
            return null;
        }
        List<ProductDTO> productDTOS = ProductMapStruct.INSTANCE.doList2DTOList(list);
        return productDTOS.stream().collect(Collectors.groupingBy(ProductDTO::getMenuGuid));
    }

    @Override
    public ProductDTO getFullName(Long productGuid) {

        return null;
    }
}
